Skip to content

Conversation

@jpnurmi
Copy link
Collaborator

@jpnurmi jpnurmi commented Sep 18, 2025

📜 Description

Prevent the Cocoa SDK from capturing managed .NET exceptions.

First of all, we need to avoid overriding Mono's Mach exception port for EXC_BAD_ACCESS and EXC_ARITHMETIC to allow handling the respective Unix signals. Secondly, Sentry's signal handler has to first invoke Mono's signal handler to give it a chance to convert it into a managed exception and redirect execution into the managed runtime’s exception handling machinery, so that managed code can catch and process the exception as if it were a normal .NET exception. Finally, Sentry's crash capturing kicks in only if we do not detect instruction or stack pointer modifications in the context.

💡 Motivation and Context

Fixes a long-standing issue with redundant crash events with Sentry.NET on iOS:

See also similar Sentry Native changes for Android:

💚 How did you test it?

  1. With the newly developed Sentry .NET integration test for iOS:
  2. Manually with Sentry.Samples.Maui in Sentry.NET:

📝 Checklist

You have to check all boxes before merging:

  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

@codecov
Copy link

codecov bot commented Sep 18, 2025

Codecov Report

❌ Patch coverage is 33.33333% with 28 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.421%. Comparing base (dced702) to head (df48cc1).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...ash/Recording/Monitors/SentryCrashMonitor_Signal.c 0.000% 24 Missing ⚠️
...ording/Monitors/SentryCrashMonitor_MachException.c 25.000% 3 Missing ⚠️
Sources/Sentry/PrivateSentrySDKOnly.m 50.000% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #6193       +/-   ##
=============================================
- Coverage   85.506%   85.421%   -0.086%     
=============================================
  Files          451       451               
  Lines        27565     27602       +37     
  Branches     12066     12079       +13     
=============================================
+ Hits         23570     23578        +8     
- Misses        3951      3979       +28     
- Partials        44        45        +1     
Files with missing lines Coverage Δ
Sources/Sentry/SentryCrashIntegration.m 100.000% <100.000%> (ø)
...entryCrash/Recording/Monitors/SentryCrashMonitor.c 80.952% <100.000%> (+0.624%) ⬆️
...SentryCrash/Recording/Tools/SentryCrashCPU_arm64.c 100.000% <100.000%> (ø)
Sources/Sentry/PrivateSentrySDKOnly.m 81.818% <50.000%> (-0.535%) ⬇️
...ording/Monitors/SentryCrashMonitor_MachException.c 35.123% <25.000%> (-0.171%) ⬇️
...ash/Recording/Monitors/SentryCrashMonitor_Signal.c 49.253% <0.000%> (-9.675%) ⬇️

... and 5 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dced702...df48cc1. Read the comment docs.

jpnurmi added a commit to getsentry/sentry-dotnet that referenced this pull request Sep 18, 2025
This reverts "Use pre-built version of sentry-cocoa SDK (#3727)"
commit d179ec9 and restores the
modules/sentry-cocoa Git module checked out at:
getsentry/sentry-cocoa#6193
@jpnurmi jpnurmi force-pushed the jpnurmi/mono-interop branch 2 times, most recently from 2f90356 to ed98b04 Compare September 18, 2025 11:46
@github-actions
Copy link
Contributor

github-actions bot commented Sep 18, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1208.65 ms 1245.50 ms 36.85 ms
Size 23.75 KiB 1.01 MiB 1016.19 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
bc0a04c 1226.83 ms 1255.04 ms 28.21 ms
e8f9a1d 1229.02 ms 1264.17 ms 35.15 ms
2a36c3f 1227.27 ms 1246.89 ms 19.63 ms
5712478 1220.10 ms 1239.69 ms 19.59 ms
fd5961e 1210.59 ms 1235.57 ms 24.98 ms
3b373bb 1218.19 ms 1250.57 ms 32.38 ms
8fd192f 1202.10 ms 1220.19 ms 18.09 ms
bbe6658 1221.00 ms 1248.51 ms 27.51 ms
cd67f52 1216.29 ms 1255.27 ms 38.99 ms
07d7e83 1211.71 ms 1240.08 ms 28.37 ms

App size

Revision Plain With Sentry Diff
bc0a04c 23.75 KiB 933.32 KiB 909.57 KiB
e8f9a1d 23.75 KiB 969.78 KiB 946.04 KiB
2a36c3f 23.75 KiB 874.45 KiB 850.71 KiB
5712478 23.75 KiB 969.28 KiB 945.54 KiB
fd5961e 23.74 KiB 874.07 KiB 850.32 KiB
3b373bb 23.75 KiB 947.72 KiB 923.97 KiB
8fd192f 23.74 KiB 872.75 KiB 849.01 KiB
bbe6658 23.75 KiB 908.02 KiB 884.27 KiB
cd67f52 23.75 KiB 1.01 MiB 1016.04 KiB
07d7e83 23.75 KiB 913.27 KiB 889.52 KiB

Previous results on branch: jpnurmi/mono-interop

Startup times

Revision Plain With Sentry Diff
d171c8f 1226.86 ms 1256.95 ms 30.09 ms
f651762 1232.57 ms 1259.68 ms 27.11 ms

App size

Revision Plain With Sentry Diff
d171c8f 23.75 KiB 1.02 MiB 1016.31 KiB
f651762 23.75 KiB 975.29 KiB 951.55 KiB

@jpnurmi
Copy link
Collaborator Author

jpnurmi commented Sep 18, 2025

Screen.Recording.2025-09-18.at.11.54.52.mov

@jpnurmi jpnurmi changed the title [WIP] fix: interop with managed Mono/CoreCLR runtimes [WIP] fix: interop with managed .NET runtimes Sep 29, 2025
@jpnurmi jpnurmi force-pushed the jpnurmi/mono-interop branch from ed98b04 to 8559ea9 Compare October 28, 2025 12:47
@jpnurmi jpnurmi changed the title [WIP] fix: interop with managed .NET runtimes [WIP] fix: AOT interop with managed .NET runtimes Oct 28, 2025
@jpnurmi jpnurmi changed the base branch from main to v8.x October 28, 2025 12:58
@jpnurmi jpnurmi force-pushed the jpnurmi/mono-interop branch from db30de0 to dd33f14 Compare October 28, 2025 16:20
@jpnurmi jpnurmi changed the base branch from v8.x to main October 28, 2025 16:20
@jpnurmi jpnurmi force-pushed the jpnurmi/mono-interop branch from dd33f14 to e51c82e Compare October 29, 2025 13:13
@jpnurmi jpnurmi changed the title [WIP] fix: AOT interop with managed .NET runtimes fix: AOT interop with managed .NET runtimes Nov 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants